package com.example.graduate.controller;
import com.alibaba.fastjson.JSONObject;
import com.example.graduate.dto.LoginRequest;
import com.example.graduate.response.DataResponse;
import com.example.graduate.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(value = "/login",produces = MediaType.APPLICATION_JSON_VALUE)
public class LoginController {
    @Autowired
    UserService userService;

    @PostMapping("/toLogin")
    public DataResponse login(@RequestBody LoginRequest loginRequest){
        log.info("【登录接口】登陆请求:{}", JSONObject.toJSONString(loginRequest));
        DataResponse login = userService.login(loginRequest);
        log.info("【登录接口】登陆请求响应:{}", JSONObject.toJSONString(login));
        return login;
    }
}
